# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=musl
_mingw_suff=midipix-cross
_base_ver=1.1.9
pkgname=("${_mingw_suff}-${_realname}")
provides=("${_mingw_suff}-libc")
conflicts=("${_mingw_suff}-libc")
pkgver=1.1.9.36.44d991d
pkgrel=1
pkgdesc="Stub for the midipix system call layer"
arch=('i686' 'x86_64')
url="http://midipix.org"
groups=("${_mingw_suff}-toolchain" "${_mingw_suff}")
depends=("zlib")
makedepends=("${_mingw_suff}-gcc" 'make')
options=('!strip' 'staticlibs' '!emptydirs' '!buildflags')
source=("http://www.musl-libc.org/releases/${_realname}-${_base_ver}.tar.gz"
        "git+git://midipix.org/mmglue"
        "git+git://midipix.org/lazy")

md5sums=('14e8c5ac74f887d53256b3dcaf9b4aaa'
         'SKIP'
         'SKIP')

#noextract=("${_realname}-${_base_ver}.tar.gz")
#not supported yet
#i686-nt32-midipix
_targets="x86_64-nt64-midipix"

pkgver() {
  cd "$srcdir/mmglue"
  printf "%s.%s.%s" "${_base_ver}" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  #mv ${srcdir}/${_realname}-${_base_ver} ${srcdir}/${_realname}
  cd "${srcdir}/$_realname-${_base_ver}" 
  cp -R ../mmglue/* .
}


build() {
  [ -d ${srcdir}/build-$(arch) ] && rm -rf ${srcdir}/build-$(arch)
  mkdir ${srcdir}/build-$(arch)
  cd ${srcdir}/build-$(arch)

  for _target in ${_targets}; do
    ../lazy/lazy \
    -x config \
    -t "${_target}" \
    -a nt64 \
    -c gcc \
    -n musl \
    -p "../$_realname-${_base_ver}" \
    -f "${pkgdir}/opt/${_target}"
  done
}

package() {
  cd ${srcdir}/build-$(arch)
  for _target in ${_targets}; do
    #stage 1
    #./lazy -x build -e install_no_complex
    #stage 2
    PATH=/opt/bin:$PATH ./lazy -x build -e install
  done
}
